repo: Update HEAD after a commit
authorColin Walters <walters@verbum.org>
Sat, 15 Oct 2011 02:56:40 +0000 (22:56 -0400)
committerColin Walters <walters@verbum.org>
Sat, 15 Oct 2011 02:56:40 +0000 (22:56 -0400)
src/libhacktree/hacktree-repo.c

index 5ee6ce1b1a4c89efbaf0aba711e372ef8e715628..2a4b74b3cf553bbca63759e4456612f8cae4d519 100644 (file)
@@ -193,6 +193,10 @@ parse_checksum_file (HacktreeRepo   *self,
           goto out;
         }
     }
+  else
+    {
+      g_strchomp (ret_sha256);
+    }
 
   *sha256 = ret_sha256;
   ret = TRUE;
@@ -200,6 +204,25 @@ parse_checksum_file (HacktreeRepo   *self,
   return ret;
 }
 
+static gboolean
+write_checksum_file (const char *path,
+                     const char *sha256,
+                     GError    **error)
+{
+  gboolean ret = FALSE;
+  char *buf = NULL;
+
+  buf = g_strconcat (sha256, "\n", NULL);
+  
+  if (!g_file_set_contents (path, buf, -1, error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  g_free (buf);
+  return ret;
+}
+
 gboolean
 hacktree_repo_check (HacktreeRepo *self, GError **error)
 {
@@ -1207,6 +1230,12 @@ hacktree_repo_commit (HacktreeRepo *self,
                                commit, &ret_commit_checksum, error))
     goto out;
 
+  if (!write_checksum_file (priv->head_ref_path, g_checksum_get_string (ret_commit_checksum), error))
+    goto out;
+
+  g_free (priv->current_head);
+  priv->current_head = g_strdup (g_checksum_get_string (ret_commit_checksum));
+
   ret = TRUE;
  out:
   if (!ret)